// 代码自动生成，请勿更改
using System;
using System.Text;
using Se.Model;
using System.Collections.Generic;
using Se.Protocol;

namespace Se.Model.Generator
{
    /// <summary>
    /// 对于接受到的数据包进行进一步的处理
    /// </summary>
	public class ClientReceivedHandler
	{
		private IClientReceived Handler;

        public ClientReceivedHandler(IClientReceived handler)
        {
            this.Handler = handler;
        }
		
		public void Handle(ClientMessage package)
		{
			var g_messageType = package.Type;
            var g_field = package[ClientMessage.Descriptor.FindFieldByNumber((int)g_messageType)];
			switch(g_messageType)
			{

				case ClientMessage.Types.ClientType.ErrorInfo:
					var g_field_ErrorInfo = g_field as ErrorInfo;
					this.Handle_ErrorInfo(g_field_ErrorInfo);
					break;
				case ClientMessage.Types.ClientType.LoginOK:
					var g_field_LoginOK = g_field as LoginOK;
					this.Handle_LoginOK(g_field_LoginOK);
					break;
				case ClientMessage.Types.ClientType.RegisterOK:
					var g_field_RegisterOK = g_field as RegisterOK;
					this.Handle_RegisterOK(g_field_RegisterOK);
					break;
				case ClientMessage.Types.ClientType.UpdateChatMsg:
					var g_field_UpdateChatMsg = g_field as UpdateChatMsg;
					this.Handle_UpdateChatMsg(g_field_UpdateChatMsg);
					break;
				case ClientMessage.Types.ClientType.CreatePlayerSuccess:
					var g_field_CreatePlayerSuccess = g_field as CreatePlayerSuccess;
					this.Handle_CreatePlayerSuccess(g_field_CreatePlayerSuccess);
					break;
			}
		}


		private void Handle_ErrorInfo(ErrorInfo package)
		{
			this.Handler.PtRequest_ErrorInfo(package.ErrorType, package.Msg);
		}		

		private void Handle_LoginOK(LoginOK package)
		{
			this.Handler.PtRequest_LoginOK(package.AccountID, package.UserName, package.Message);
		}		

		private void Handle_RegisterOK(RegisterOK package)
		{
			this.Handler.PtRequest_RegisterOK(package.AccountID, package.UserName);
		}		

		private void Handle_UpdateChatMsg(UpdateChatMsg package)
		{
			this.Handler.PtRequest_UpdateChatMsg(package.ContentList);
		}		

		private void Handle_CreatePlayerSuccess(CreatePlayerSuccess package)
		{
			this.Handler.PtRequest_CreatePlayerSuccess(package.Id, package.Name, package.RoleTypeID);
		}		
	}

	public interface IClientReceived
	{
		void PtRequest_ErrorInfo(Int32 errorType, String msg);
		void PtRequest_LoginOK(Int64 accountID, String userName, String message);
		void PtRequest_RegisterOK(Int64 accountID, String userName);
		void PtRequest_UpdateChatMsg(IList<ChatMsg> content);
		void PtRequest_CreatePlayerSuccess(Int64 id, String name, Int32 roleTypeID);
	}



	public static class PC_Send
	{

		public static byte[] ErrorInfo(Int32 errorType, String msg)
		{
			ServerMessage.Builder g_commonMessage = new ServerMessage.Builder();
			ErrorInfo.Builder g_msg = new ErrorInfo.Builder();
			g_msg.SetErrorType(errorType).SetMsg(msg);
			g_commonMessage.SetType(ServerMessage.Types.ServerType.ErrorInfo);
			g_commonMessage.SetErrorInfo(g_msg);
            return g_commonMessage.Build().ToByteArray();
		}

		public static byte[] Login(String userName, String pwd)
		{
			ServerMessage.Builder g_commonMessage = new ServerMessage.Builder();
			Login.Builder g_msg = new Login.Builder();
			g_msg.SetUserName(userName).SetPwd(pwd);
			g_commonMessage.SetType(ServerMessage.Types.ServerType.Login);
			g_commonMessage.SetLogin(g_msg);
            return g_commonMessage.Build().ToByteArray();
		}

		public static byte[] Register(String userName, String pwd)
		{
			ServerMessage.Builder g_commonMessage = new ServerMessage.Builder();
			Register.Builder g_msg = new Register.Builder();
			g_msg.SetUserName(userName).SetPwd(pwd);
			g_commonMessage.SetType(ServerMessage.Types.ServerType.Register);
			g_commonMessage.SetRegister(g_msg);
            return g_commonMessage.Build().ToByteArray();
		}

		public static byte[] Chat(Int32 msgType, String message)
		{
			ServerMessage.Builder g_commonMessage = new ServerMessage.Builder();
			Chat.Builder g_msg = new Chat.Builder();
			g_msg.SetMsgType(msgType).SetMessage(message);
			g_commonMessage.SetType(ServerMessage.Types.ServerType.Chat);
			g_commonMessage.SetChat(g_msg);
            return g_commonMessage.Build().ToByteArray();
		}

		public static byte[] CreatePlayer(String name, Int32 roleTypeID)
		{
			ServerMessage.Builder g_commonMessage = new ServerMessage.Builder();
			CreatePlayer.Builder g_msg = new CreatePlayer.Builder();
			g_msg.SetName(name).SetRoleTypeID(roleTypeID);
			g_commonMessage.SetType(ServerMessage.Types.ServerType.CreatePlayer);
			g_commonMessage.SetCreatePlayer(g_msg);
            return g_commonMessage.Build().ToByteArray();
		}
	}
}
